<template>

    <div class="app-container" v-if="canList">
        <div class="filter-container">
            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="单号"
                      v-model="listQuery.entity.mallOrder.orderNo">
            </el-input>
            <!--            <el-input @keyup.enter.native="handleFilter" style="width: 200px;"  class="filter-item input"-->
            <!--                      placeholder="用户ID"-->
            <!--                      v-model="listQuery.entity.userId">-->
            <!--            </el-input>-->

            <!--            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"-->
            <!--                      placeholder="下单人姓名"-->
            <!--                      v-model="listQuery.entity.user.name">-->
            <!--            </el-input>-->

            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"
                      placeholder="转出方编号"
                      v-model="listQuery.entity.fromUser.code">
            </el-input>

            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"
                      placeholder="接收方编号"
                      v-model="listQuery.entity.user.code">
            </el-input>

            <el-input v-if="type==1" style="width: 100px" class="filter-item input"
                      placeholder="收货人姓名"
                      v-model="listQuery.entity.mallOrder.userName">
            </el-input>
            <el-input style="width: 100px" class="filter-item input"
                      placeholder="店铺名"
                      v-model="listQuery.entity.shopEntity.name">
            </el-input>

            <el-input v-if="type==1" style="width: 120px;" class="filter-item input"
                      placeholder="收货人手机"
                      v-model="listQuery.entity.mallOrder.mobile">
            </el-input>

            <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.orderType"
                       placeholder="订单类型">
                <el-option v-for="(item,index) in  orderTypeOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

                        <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                                   style="width: 110px;margin-left: 20px;"
                                   v-model="listQuery.entity.mallOrder.busType"
                                   placeholder="业务类型">
                            <el-option v-for="(item,index) in  busTypeOptions" :key="item" :label="item" :value="index">
                            </el-option>
                        </el-select>

        <!--    <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.orderFrom"
                       placeholder="订单来源">
                <el-option v-for="(item,index) in  orderFromOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>-->


            <el-select v-if="type==0&&listQuery.entity.mallOrder.orderFrom==0" @change='handleFilter' clearable
                       class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.payStatus"
                       placeholder="支付状态">
                <el-option v-for="(item,index) in  payStatusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>


            <el-select v-if="type==1" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.orderStatus"
                       placeholder="订单状态">
                <el-option v-for="(item,index) in  orderStatusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

            <el-date-picker

                    v-model="listQuery.entity.mallOrder.orderTimes"
                    type="datetimerange"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    range-separator="至"
                    start-placeholder="下单时间开始日期"
                    end-placeholder="下单时间结束日期">
            </el-date-picker>


            <el-date-picker
                    v-if="listQuery.entity.mallOrder.orderStatus&&listQuery.entity.mallOrder.orderStatus>1"
                    v-model="listQuery.entity.mallOrder.deliverTimes"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="发货时间开始日期"
                    end-placeholder="发货时间结束日期">
            </el-date-picker>


            <!--            <el-date-picker-->
            <!--                    v-model="refundTime"-->
            <!--                    type="datetimerange"-->
            <!--                    range-separator="至"-->
            <!--                    start-placeholder="退款时间开始日期"-->
            <!--                    end-placeholder="退款时间结束日期">-->
            <!--            </el-date-picker>-->

            <div style="margin-top: 10px">


                <el-button style="" class="filter-item input" type="primary" v-waves icon="el-icon-search"
                           @click="handleFilter">查找
                </el-button>

                <el-button v-if="type==1" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-download"
                           @click="downLoad">发货下载
                </el-button>

                <el-button v-if="type==1" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-upload2"
                           @click="openFile">上传订单
                </el-button>


                <el-button v-if="type==1" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-refresh-right"
                           @click="renew">恢复下载
                </el-button>

                <input style="display: none" ref="file" @change="upload" type="file">

                <!--            <el-button  class="filter-item input" style="margin-left: 10px;" @click="handleCreate" type="primary"-->
                <!--                       v-if="canSave" icon="el-icon-edit">添加-->
                <!--            </el-button>-->
                <!--                <el-button  class="filter-item input" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download"-->
                <!--                           @click="handleDownload">导出-->
                <!--                </el-button>-->
            </div>
        </div>

        <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
                  style="width: 100%;">
            <!--            <el-table-column align="center" label="序号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.$index+1}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="店铺名" width="180">
                <template slot-scope="scope">
                    <span>{{scope.row.shopEntity?scope.row.shopEntity.name:getShopName}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="单号" width="180">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.orderNo}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="type==0&&listQuery.entity.mallOrder.orderFrom==0" align="center" label="下单人"
                             width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.user">{{scope.row.user.code}}-{{scope.row.user.name}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==0" align="center" label="转出方" width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.fromUser">{{scope.row.fromUser.code}}-{{scope.row.fromUser.name}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==0" align="center" label="接收方" width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.user">{{scope.row.user.code}}-{{scope.row.user.name}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="编号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.code}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="收货人" v-if="listQuery.entity.mallOrder.orderType==0">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.userName}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="收货人电话" width="120" v-if="listQuery.entity.mallOrder.orderType==0">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.mobile}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="type==0" align="center" label="总价">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.price}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==1" width="180" align="center" label="物流号">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.logNo}}</span>
                </template>
            </el-table-column>

            <!--            <el-table-column v-if="type==1" align="center" label="物流公司">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logCompany}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

            <el-table-column v-if="type==1" align="center" label="物流费">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.logFee}}</span>
                </template>
            </el-table-column>

            <!--            <el-table-column align="center" label="物流费">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logFee}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="物流公司">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logCompany}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="物流单号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logNo}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="收货地址">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.address}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="订单状态">-->
            <!--                <template slot-scope="scope">-->
            <!--                                                <span>-->

            <!--                         <el-tag :type="tagTypes[scope.row.mallOrder.orderStatus]">     {{orderStatusOptions[scope.row.mallOrder.orderStatus]} }</el-tag>-->

            <!--                        </span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

    <!--        <el-table-column align="center" label="订单来源" v-if="type==0">
                <template slot-scope="scope"><span>

                         <el-tag :type="tagTypes[scope.row.mallOrder.orderFrom]">     {{orderFromOptions[scope.row.mallOrder.orderFrom]}}</el-tag>

                        </span>
                </template>
            </el-table-column>-->

                        <el-table-column align="center" label="业务类型" v-if="type==0">
                            <template slot-scope="scope"><span>

                                     <el-tag :type="tagTypes[scope.row.mallOrder.busType]">     {{busTypeOptions[scope.row.mallOrder.busType]}}</el-tag>

                                    </span>
                            </template>
                        </el-table-column>

            <el-table-column align="center" label="订单类型" v-if="type==0">
                <template slot-scope="scope"><span>

                         <el-tag :type="tagTypes[scope.row.mallOrder.orderType]">     {{orderTypeOptions[scope.row.mallOrder.orderType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="支付状态" v-if="type==0">
                <template slot-scope="scope"><span >
                         <el-tag :type="tagTypes[scope.row.mallOrder.payStatus]">     {{payStatusOptions[scope.row.mallOrder.payStatus]}}</el-tag>

                        </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="订单状态" >
                <template slot-scope="scope"><span>

                         <el-tag :type="tagTypes[scope.row.mallOrder.orderStatus]">{{orderStatusOptions[scope.row.mallOrder.orderStatus]}}</el-tag>

                        </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="下单时间" width="160">
                <template slot-scope="scope">
                    <span>{{parseTime(scope.row.mallOrder.orderTime)}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="支付时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.payTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="发货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.deliverTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="确认收货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.confirmTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="退货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.backTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="退款时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.refundTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="拒绝时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.refuseTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

            <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="info" v-if="canUpdate" size="mini" @click="handleItems(scope.row.mallOrder.id)">详情
                    </el-button>
                    <el-button  type="primary" v-if="canUpdate&&type==1" size="mini" @click="handleUpdate(scope)">编辑
                    </el-button>
                    <el-button v-if="canDelete&&type==0&&scope.row.mallOrder.cancel" size="mini" type="danger"
                               @click="close(scope.$index)">取消
                    </el-button>
<!--                    <el-button v-if="canDelete&&type==0&&scope.row.mallOrder.orderType==0&&scope.row.mallOrder.orderFrom==0&&scope.row.mallOrder.payStatus==0" size="mini" type="danger"-->
<!--                               @click="pay(scope.$index)">支付-->
<!--                    </el-button>-->
                </template>
            </el-table-column>

        </el-table>

        <div class="pagination-container" style="margin-top: 20px">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                           layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>


        <el-dialog width="60%" center title="订单详情" v-if="temp.mallOrder" :visible.sync="dialogTableVisible">
            <div class="order-detail">
                <div class="item">
                    <div class="item-con">
                        <span class="key">订单编号</span>
                        <span class="value">{{temp.mallOrder.orderNo}}</span>
                    </div>
                </div>

                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">联系电话</span>
                    <span class="value">{{temp.mallOrder.mobile}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">订单状态</span>
                    <span class="value">{{orderStatusOptions[temp.mallOrder.orderStatus]}}</span>
                </div>
                <div class="item">
                    <span class="key">订单来源</span>
                    <span class="value">{{orderFromOptions[temp.mallOrder.orderFrom]}}</span>
                </div>
                <div class="item">
                    <span class="key">订单类型</span>
                    <span class="value">{{orderTypeOptions[temp.mallOrder.orderType]}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderFrom==0">
                    <span class="key">付款状态</span>
                    <span class="value">{{payStatusOptions[temp.mallOrder.payStatus]}}</span>
                </div>
                <div class="item">
                    <span class="key">订单金额</span>
                    <span class="value">{{temp.mallOrder.price}}</span>
                </div>
                <div class="item">
                    <span class="key">订单积分</span>
                    <span class="value">{{temp.mallOrder.point}}</span>
                </div>
                <div class="item">
                    <span class="key">订单优惠券</span>
                    <span class="value">{{temp.mallOrder.coupon}}</span>
                </div>
                <div class="item">
                    <span class="key">订单购物卷</span>
                    <span class="value">{{temp.mallOrder.voucher}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">物流单号</span>
                    <span class="value">{{temp.mallOrder.logNo}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">物流公司</span>
                    <span class="value">{{temp.mallOrder.logCompany}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">收货地址</span>
                    <span class="value">{{temp.mallOrder.address}}</span>
                </div>
                <div class="item">
                    <span class="key">下单时间</span>
                    <span class="value">{{parseTime(temp.mallOrder.orderTime)}}</span>
                </div>
                <!--                <div class="item">-->
                <!--                    <span class="key">支付时间</span>-->
                <!--                    <span class="value">{{parseTime(temp.mallOrder.payStatus)}}</span>-->
                <!--                </div>-->
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">发货时间</span>
                    <span class="value"
                          v-if="temp.mallOrder.deliverTime">{{parseTime(temp.mallOrder.deliverTime)}}</span>
                </div>

                <div class="item">
                    <span class="key">备注</span>
                    <span class="value">{{temp.mallOrder.remark}}</span>
                </div>

            </div>
            <el-divider>订单明细</el-divider>
            <el-table
                    border
                    show-summary
                    :data="temp.mallOrder.items"
                    style="width: 100%">
                <el-table-column
                        align="center"
                        prop="name"
                        label="产品"
                        width="350">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="类别"
                        width="200"
                >
                    <template slot-scope="scope">
                        {{scope.row.skuName?scope.row.skuName:'默认'}}
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="price"
                        label="价格">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="quantity"
                        label="数量">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="totalPrice"
                        label="总额">
                    <!--                    <template slot-scope="scope"><span>-->
                    <!--                        {{scope.row.quantity*scope.row.price}}-->
                    <!--                        </span>-->
                    <!--                    </template>-->
                </el-table-column>
            </el-table>

        </el-dialog>


        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" v-if="temp.mallOrder">
            <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
                     style='width: 450px; margin-left:50px;'>
                <el-form-item label="单号" prop="orderNo">
                    <el-input v-model="temp.mallOrder.orderNo"></el-input>
                </el-form-item>
                <el-form-item label="用户ID" prop="userId">
                    <el-input v-model="temp.mallOrder.userId"></el-input>
                </el-form-item>
                <el-form-item v-if="type==0" label="总价" prop="price">
                    <el-input v-model="temp.mallOrder.price"></el-input>
                </el-form-item>
                <el-form-item label="物流费" prop="logFee">
                    <el-input v-model="temp.mallOrder.logFee"></el-input>
                </el-form-item>
                <el-form-item label="物流公司" prop="logCompany">
                    <el-input v-model="temp.mallOrder.logCompany"></el-input>
                </el-form-item>
                <el-form-item label="物流单号" prop="logNo">
                    <el-input v-model="temp.mallOrder.logNo"></el-input>
                </el-form-item>
                <el-form-item label="收货地址" prop="address">
                    <el-input v-model="temp.mallOrder.address"></el-input>
                </el-form-item>
                <el-form-item label="订单状态" prop="status">
                    <el-select class="filter-item input" v-model="temp.mallOrder.orderStatus" placeholder="订单状态">
                        <el-option v-for="(item,index) in  orderStatusOptions" :key="item" :label="item"
                                   :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="支付状态" prop="status">
                    <el-select class="filter-item input" v-model="temp.mallOrder.payStatus" placeholder="支付状态">
                        <el-option v-for="(item,index) in  payStatusOptions" :key="item" :label="item"
                                   :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.orderTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="下单时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="支付时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.payTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="支付时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="发货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.deliverTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="发货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="确认收货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.confirmTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="确认收货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="退货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.backTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="退货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="退款时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.refundTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="退款时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="拒绝时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.refuseTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="拒绝时间">
                    </el-date-picker>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialogForm">取消</el-button>
                <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确认</el-button>
                <el-button v-else type="primary" @click="updateData">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style type="stylus">
    .filter-container {
        /*padding-bottom: 20px;*/
    }

    .filter-item {
        margin-bottom: 10px;
    }

    .filter-item.input {
        /*line-height: 60px*/
        margin-right: 10px;
    }
</style>

<style type="stylus" lang="stylus">
    .filter-container {
        padding-bottom: 20px;
    }

    .order-detail
        display flex
        flex-wrap wrap

        .item
            margin-bottom 20px
            display flex
            align-items center
            justify-content flex-start
            width 50%

            .value
                margin-left 20px


</style>

<script>
    import {list, save, update, remove, info} from '@/api/mall_order'
    import waves from '@/directive/waves' // 水波纹指令
    import {parseTime} from '@/utils'
    import {mapGetters} from 'vuex'
    import {hasAuth} from '@/utils/auth'
    import {downLoad, upload,renew,close,pay} from "../../../api/mall_order";

    export default {
        name: 'test',
        directives: {
            waves
        },
        mounted() {

            if (this.type == 1) {//库房
                this.listQuery.entity.mallOrder.orderType = 0//订单类型为发货
                this.listQuery.entity.mallOrder.payStatus = 1//订单已经支付
            } else {//订单
                // this.listQuery.entity.mallOrder.orderFrom = 0 // 默认
            }
        },
        props: {
            type: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                file: null,
                isLoading: false,
                tableKey: 0,
                list: null,
                total: null,
                listLoading: true,
                listQuery: {
                    json: true,
                    page: 1,
                    limit: 20,
                    order: 'mallOrder.id desc',
                    entity: {
                        mallOrder: {
                            orderNo: null
                            ,
                            userId: null
                            ,
                            price: null
                            ,
                            logFee: null
                            ,
                            logCompany: null
                            ,
                            logNo: null
                            ,
                            userName: null
                            ,
                            mobile: null
                            ,
                            address: null
                            ,
                            orderTime: null,
                            orderTimes: null,
                            payTime: null
                            ,
                            deliverTime: null
                            ,
                            confirmTime: null
                            ,
                            backTime: null
                            ,
                            refundTime: null
                            ,
                            refuseTime: null
                            ,
                            orderStatus: null
                            ,
                            payStatus: null,
                            orderFrom: null,
                            busType: null,
                            orderType: null
                        },
                        user: {
                            name: '',
                            code: ''
                        },
                        fromUser: {
                            name: '',
                            code: ''
                        },
                        shopEntity: {
                            name: '',
                        }

                    }
                },
                orderStatusOptions: ["新订单", "配货中", "已发货", "已收货", "退款中", "已退款", "已拒绝","已完成","已取消"],
                payStatusOptions: ["未支付", "已支付"],
                orderTypeOptions: ["发货", "转货"],
                orderFromOptions: ["商城", "后台","收款"],
                busTypeOptions: ["进货", "调配", "退货","还货","自动进货"],
                closedOptions: ["已结束", "未结束"],
                tagTypes: ['info', '', 'warning', 'danger', 'warning'],
                temp: {}
                ,
                dialogFormVisible: false,
                dialogTableVisible: false,
                dialogStatus:
                    '',
                textMap:
                    {
                        update: '修改',
                        create:
                            '新增'
                    }
                ,
                rules:
                    {
                        orderNo: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        userId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        price: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        orderTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        payTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        deliverTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        confirmTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        backTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        refundTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        refuseTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        orderStatus: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        payStatus: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        logFee: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        logCompany: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        logNo: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        userName: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        mobile: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        address: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                    }
                ,
                downloadLoading: false,
                qData:
                    {
                        token: '',
                        key:
                            ''
                    }
            }
        },
        created() {
            this.getList()
        },
        computed: {
            ...mapGetters([
                'perms'
            ]),
            getShopName(){
                 return process.env.VUE_APP_SHOPNAME;
            }
            ,
            canSave() {
                return hasAuth(this.perms, 'mall:order:save')
            },
            canDelete() {

                return hasAuth(this.perms, 'mall:order:delete')
            },
            canUpdate() {
                return hasAuth(this.perms, 'mall:order:update')
            },
            canList() {
                return hasAuth(this.perms, 'mall:order:list')
            }
        },
        methods: {

            parseTime(time) {
                return parseTime(time)
            },
            handleItems(id) {
                info(id).then(res => {
                    this.temp = res.data
                    this.dialogTableVisible = true
                })
            },
            getList() {
                this.listLoading = true
                list(this.listQuery).then(response => {
                    this.list = response.data.list
                    console.log(this.list)
                    this.list.forEach(item => {
                        if (item.shopEntity){
                            if (item.mallOrder.orderType == 0 && item.mallOrder.busType == 1){
                                item.shopEntity.name = process.env.VUE_APP_SHOPNAME;
                            }
                        }
                    })
                    this.total = response.data.total
                    this.listLoading = false
                })
            },
            openFile() {
                this.$refs.file.click()
            },
            upload(e) {
                upload(e.target.files[0]).then(res=>{
                    this.$notify({
                        title: '成功',
                        message: '上传成功!',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            renew(){
                this.isLoading = true
                renew().then(() => {
                    this.isLoading = false
                    this.$notify({
                        title: '成功',
                        message: '恢复成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            downLoad() {
                this.isLoading = true
                downLoad().then(() => {
                    this.isLoading = false
                    this.$notify({
                        title: '成功',
                        message: '下载成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleSizeChange(val) {
                this.listQuery.limit = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleModifyStatus(row, status) {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                row.status = status
            },
            beforeFormShow(row) {
                this.resetTemp(row) // 更新数据
                // 存在图片

            },
            afterFormShow(row) {

            },
            beforeFormCommit() {
            },
            resetTemp(row) {

                this.temp = {}
                if (row) {
                    this.temp = JSON.parse(JSON.stringify(row))
                    this.temp.mallOrder.items = []
                }


            },
            handleCreate() {
                this.beforeFormShow()
                this.resetTemp()
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.afterFormShow()
                    this.$refs['dataForm'].clearValidate()
                })
            },
            handleDelete(scope) {
                this.index = scope.$index
                // this.beforeFormShow(scope.row)
                // this.temp = Object.assign({}, row) // copy obj
                this.$confirm('此操作将取消订单退回资金, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.$message({
                    //   type: 'success',
                    //   message: '删除成功!'
                    // })
                    this.deleteData()
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            },
            createData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            save(this.temp).then(res => {
                                this.temp = res.data
                                this.list.unshift(this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '创建成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            deleteData() {
                const ids = [this.list[this.index].mallOrder.id]
                remove({ids: ids}).then(res => {
                    // 从当前队列中移除
                    this.list.splice(this.index, 1)
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                })
            },
            close(index){
                this.$confirm('此操作将取消订单退回资金, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let orderId = this.list[index].mallOrder.id
                    close(orderId).then(res=>{
                        this.$notify({
                            title: '成功',
                            message: '取消成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.list[index].mallOrder = res.data
                    })
                })
            },
            pay(index){

                this.$confirm('请确认收到款后再进行操作, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let orderId = this.list[index].mallOrder.id
                    pay(orderId).then(res=>{
                        this.$notify({
                            title: '成功',
                            message: '支付成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.list[index].mallOrder = res.data
                    })
                })
            },
            handleUpdate(scope) {
                this.index = scope.$index
                this.beforeFormShow(scope.row)
                this.dialogStatus = 'update'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                })
            },
            updateData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            update(this.temp.mallOrder).then(() => {
                                this.list.splice(this.index, 1, this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '更新成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            closeDialogForm() {
                this.dialogFormVisible = false
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => {
                        return v[j]
                    }
                ))
            },
        }
    }
</script>
